package com.ranjiaqi.compatator;

/**
 * @ClassName PersonComparator
 * @Description TODO
 * @Author hp
 * @Date 2021/6/25 8:53
 * @Version 1.0
 **/

import java.util.Comparator;

/**
 * 自定义的比较器，对象Person进行比较
 * 实现接口，重写方法
 */
public class PersonComparator implements Comparator<Person> {

    @Override
    public int compare(Person o1, Person o2) {
        int num = o1.getAge()-o2.getAge();
        return num == 0 ? o1.getName().compareTo(o2.getName()):num;
    }
}
